<template>
  <div class="mainCon">
    <div class="mainCon">
      <div class="containercontent">

        <div class="selectw100 seachTip">
          <div class="inlineblock verticalmiddle infoitem">
            <div class="inlineblock verticalmiddle">
              名称
            </div>
            <div class="inlineblock verticalmiddle informationItem">
              <el-input style="" v-model="searchName" size="mini" placeholder="分包商名" @keyup.enter.native="doSearch"></el-input>
            </div>
          </div>
          <div class="inlineblock verticalmiddle infoitem">
            <div class="inlineblock verticalmiddle">
              状态
            </div>
            <div class="inlineblock verticalmiddle informationItem">
              <el-select size="mini" v-model="enableStatusValue" @change="doSearch">
                <el-option v-for="item in enableStatus" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
              <!--<el-input style="" v-model="status" size="mini" placeholder="选择通过或待审核"></el-input>-->
            </div>
          </div>
          <div class="inlineblock basicRightDistanceA searchIcon">
            <el-button size="mini" @click="doSearch">搜索</el-button>
            <el-button size="mini" @click="emptySearch">清空</el-button>

          </div>
        </div>
        <div class="separaterowTable">
          <div class="tableTittle">
            <div>
              <span class="fontImpact">1</span>
              <span>分包商</span>
            </div>
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="addsubcontractor" style="float:right" v-if="userOpernation.add.display">添加分包商</el-button>
          </div>
          <el-table :data="subcontractorTable" style="width: 100%" class="tableCon" size="mini">
            <el-table-column label="序号" min-width="50px" fixed>
              <template slot-scope="scope">
                {{scope.$index+(subcontratorQuery.page - 1) * subcontratorQuery.pageCount + 1}}
              </template>
            </el-table-column>
            <el-table-column property="name" label="名称" min-width="100px" fixed show-overflow-tooltip>
            </el-table-column>
            <!--<el-table-column property="address" label="地址" min-width="100px" show-overflow-tooltip>
            </el-table-column>-->
            <el-table-column property="contact" label="联系人" min-width="100px" show-overflow-tooltip>
            </el-table-column>
            <el-table-column property="phone" label="联系电话" min-width="120px" show-overflow-tooltip>
            </el-table-column>
            <el-table-column property="haveCnas" label="CNAS资质" min-width="90px">
              <template slot-scope="scope">
                <el-checkbox v-model="scope.row.haveCnas" @change="changeHas(scope.$index,'hasCNAS',scope.row.hasCNAS)" disabled></el-checkbox>
              </template>
            </el-table-column>
            <el-table-column property="haveCma" label="CMA资质" min-width="90px">
              <template slot-scope="scope">
                <el-checkbox v-model="scope.row.haveCma" @change="changeHas(scope.$index,'hasCMA',scope.row.hasCMA)" disabled></el-checkbox>
              </template>
            </el-table-column>
            <el-table-column property="status" label="状态" :formatter="formatter" min-width="80px">
            </el-table-column>
            <el-table-column property="lastAuditDate" label="最新审核日期" :formatter="formatterDate" min-width="100px">
            </el-table-column>
            <el-table-column property="planAuditDate" label="计划评审日期" min-width="100px" :formatter="formatterDate">
            </el-table-column>
            <el-table-column label="操作" min-width="200px">
              <template slot-scope="scope">
                <el-button v-if="scope.row.status=='1' && userOpernation.disable.display" type="text" size="mini" @click="isStart(scope.row)">停用</el-button>
                <el-button v-if="scope.row.status=='0' && userOpernation.enable.display" type="text" size="mini" @click="isStart(scope.row)">启用</el-button>
                <el-button v-if="scope.row.isApprove" type="text" size="mini" @click="editSubcontractor(scope.row,'review')">审核</el-button>
                <el-button type="text" size="mini" @click="editSubcontractor(scope.row,'edit')" v-if="(scope.row.status =='2' || scope.row.status =='4') && userOpernation.update.display">编辑</el-button>
                <el-button type="text" size="mini" @click="editSubcontractor(scope.row,'openEdit')" v-if="(scope.row.status =='1') && userOpernation.openUpdate.display">编辑</el-button>

                <el-button type="text" size="mini" @click="editSubcontractor(scope.row,'look')" v-if="userOpernation.select.display">详情</el-button>
                <el-button type="text" size="mini" @click="delSubcontractor(scope.row)" v-if="scope.row.status =='2' && userOpernation.delete.display">删除</el-button>
                <!---->
              </template>
            </el-table-column>
          </el-table>
          <div class="block changepages">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="subcontratorQuery.page" :page-sizes="[20,30,40]" :page-size="subcontratorQuery.pageCount" layout="total, sizes, prev, pager, next, jumper" :total="rowNumber">
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
   
    <div v-if="subcontractorPop">
      <div class="twoStageWindow subcontractorPop" style="overflow:hidden">
        <div class="twoStageWindowTitle">
          {{newOrEdit=='new'?'新增':(newOrEdit=='edit' || newOrEdit=='openEdit'?'编辑':'查看')}}分包商
          <div class="twoStageWindowClose">
             <el-button size="mini" @click="close('subcontractorForm')">取消</el-button>
          </div>
        </div>
        <div class="containercontent" style="margin-top:40px;height:99%;padding: 10px;">
          <el-tabs v-model="activeName" type="card" size="mini" class = "typeOfCard">
            <el-tab-pane label="基本信息" name="first">
              <div class="save_btn" v-if="newOrEdit != 'look' && newOrEdit != 'review'">
                  <el-button type="primary" v-if="newOrEdit == 'new' || (isStatus == 2 && newOrEdit != 'look')" style = "float:right;" @click="submitSubcontractor('save')" size="mini" :disabled="!isRepeat">保 存</el-button>
                  <el-button size="mini" type="primary" @click="submitSubcontractor('commit')" :disabled="!isRepeat" style = "float:right;margin-right:8px;">提交</el-button>
              
                
              </div>
              <div class="save_btn" v-if="newOrEdit == 'review'">
                <el-button size="mini" type="primary" @click="reviewFlowPop()" style = "float:right;">审核</el-button>
              </div>
              <el-form label-width="110px" :inline="false" class="demo-form-inline subForm" :model="subcontractorForm" :rules="subcontractorRules" ref="subcontractorForm">

                <el-form-item label="名称" prop='name'>
                  <el-col :span="22">
                    <el-input size="mini" placeholder="名称" v-model="subcontractorForm.name" :disabled="!canEdit"></el-input>

                  </el-col>
                </el-form-item>
                <el-form-item label="地址" prop='address'>
                  <el-col :span="22">
                    <el-input size="mini" placeholder="地址" v-model="subcontractorForm.address" :disabled="!canEdit"></el-input>
                  </el-col>
                </el-form-item>
                <el-form-item label="联系人" prop='contact'>
                  <el-col :span="22">
                    <el-input size="mini" placeholder="联系人" v-model="subcontractorForm.contact" :disabled="!canEdit"></el-input>
                  </el-col>
                </el-form-item>
                <el-form-item label="电话" prop='phone'>
                  <el-col :span="22">
                    <el-input size="mini" placeholder="电话" v-model="subcontractorForm.phone" :disabled="!canEdit"></el-input>
                  </el-col>
                </el-form-item>

                <el-form-item label="计划评审日期" prop='planAuditDate'>
                  <el-col :span="22">
                    <el-date-picker v-model="subcontractorForm.planAuditDate" type="date" size="mini" style="width:100%;" :disabled="!canEdit" format="yyyy-MM-dd" value-format="yyyy-MM-dd" :picker-options="pickerOptions" placeholder="选择日期">
                    </el-date-picker>
                  </el-col>
                </el-form-item>
                <el-form-item label="CNAS资质" prop='haveCnas' style="width:24%">
                  <el-col :span="22">
                    <el-checkbox v-model="subcontractorForm.haveCnas" :disabled="!canEdit"></el-checkbox>
                  </el-col>
                </el-form-item>
                <el-form-item label="CMA资质" prop='haveCma' style="width:24%">
                  <el-col :span="22">
                    <el-checkbox v-model="subcontractorForm.haveCma" :disabled="!canEdit"></el-checkbox>
                  </el-col>
                </el-form-item>
              </el-form>
              <div class="elTab">
                <el-tabs style="width: 100%;" v-model="activeTab">
                  <el-tab-pane label="附件" name="first">
                    <form style='visibility: hidden;width: 0;height: 0;'>
                      <input type="file" name="file" id="sub-file" @change="getFile" multiple="multiple">
                    </form>
                    <el-button @click="uploadClick" type="primary" size="mini" style="float:right;margin-bottom:5px" v-if="newOrEdit != 'look' && newOrEdit != 'review' && newOrEdit != 'openEdit'">上传</el-button>

                    <el-table :data="subcontractorForm.files" style="width: 100%;height:calc(100% - 43px)" size="mini" class="tableCon">
                      <el-table-column label="序号" min-width="50px">
                        <template slot-scope="scope">
                          {{scope.$index+1}}
                        </template>
                      </el-table-column>
                      <el-table-column property="fileName" label="附件名称" min-width="200px" :show-overflow-tooltip="true">
                      </el-table-column>
                      <el-table-column label="操作" min-width="100px" v-if="newOrEdit != 'look' && newOrEdit != 'review'&& newOrEdit != 'openEdit'">
                        <template slot-scope="scope">
                          <el-button type="text" size="mini" @click="deleteFileNew(scope.$index)" v-if="scope.row.id == undefined && userOpernation.delete.display">删除</el-button>
                          <el-button type="text" size="mini" @click="deleteFileEdit(scope.row,scope.$index)" v-if="scope.row.id != undefined && userOpernation.delete.display">删除</el-button>
                          <el-button type="text" size="mini" @click="downloadattachment(scope.row)" v-if="scope.row.id != undefined && userOpernation.upload.display">下载</el-button>
                        </template>
                      </el-table-column>
                      <el-table-column label="操作" min-width="100px" v-if="newOrEdit == 'look' || newOrEdit == 'review' || newOrEdit == 'openEdit'">
                        <template slot-scope="scope">
                          <el-button type="text" size="mini" @click="downloadattachment(scope.row)" v-if="scope.row.id != undefined && userOpernation.upload.display">下载</el-button>
                        </template>
                      </el-table-column>
                    </el-table>
                  </el-tab-pane>
                 
                </el-tabs>
              </div>
            </el-tab-pane>
            <el-tab-pane label="检测方法" name="second">
                  <div class = "selectw100 seachTip">
                    <div class="inlineblock verticalmiddle infoitem">
                      <div class="inlineblock verticalmiddle">
                        检测方法
                      </div>
                      <div class="inlineblock verticalmiddle informationItem">
                        <el-input  v-model="methodName" size="mini" placeholder="方法名" @keyup.enter.native="doSearchMethod"></el-input>
                      </div>
                    </div>
                    
                    <div class="inlineblock verticalmiddle infoitem">
                      <div class="inlineblock verticalmiddle">
                        能力参数
                      </div>
                      <div class="inlineblock verticalmiddle informationItem">
                        <el-input  v-model="abilityName" size="mini" placeholder="方法名" @keyup.enter.native="doSearchMethod"></el-input>
                      </div>
                    </div>
                    <el-button size="mini" type="warning" @click="doSearchMethod" style = "margin-left:10px;">搜索</el-button>
                   
                   
                    <el-button size="mini" type="primary" @click="addAbility" style = "float:right;" v-if = "newOrEdit != 'look' && newOrEdit != 'review'">添加</el-button>
                    <!--<el-button size="mini" type="primary" @click="addSubconMethod" style = "float:right;margin-right:8px;">保存</el-button>-->
                    
                  </div>
                 <el-table :data="methodsData" style="width: 100%;height:calc(100% - 83px)" size="mini" class="tableCon">
                      <el-table-column label="序号" min-width="50px">
                        <template slot-scope="scope">
                          {{scope.$index+(readQuery.page - 1) * readQuery.pageCount + 1}}
                        </template>
                      </el-table-column>
                      <el-table-column property="methodName" label="检测方法" min-width="180px">
                          <!--<template slot-scope="scope">
                              <el-input  v-model="scope.row.methodName" size="mini" placeholder="请输入"></el-input>
                          </template>-->
                      </el-table-column>
                      <el-table-column property="name" label="能力参数" min-width="180px">
                        <!--<template slot-scope="scope">
                            <el-input  v-model="scope.row.name" size="mini" placeholder="请输入"></el-input>
                        </template>-->
                      </el-table-column>
                      <!--<el-table-column property="name" label="单位" min-width="200px" :show-overflow-tooltip="true">
                      </el-table-column>-->
                      <el-table-column label="操作" min-width="100px" v-if = "newOrEdit != 'look' && newOrEdit != 'review'">
                        <template slot-scope="scope">
                          <el-button type="text" size="mini" @click = "addItem(scope.row,'edit')">设置</el-button>
                          <el-button type="text" size="mini" @click = "deleteMethod(scope.row)">删除</el-button>
                        </template>
                      </el-table-column>
                       <el-table-column label="操作" min-width="100px" v-if = "newOrEdit == 'look' || newOrEdit == 'review'">
                        <template slot-scope="scope">
                          <el-button type="text" size="mini" @click = "addItem(scope.row,'look')">详情</el-button>
                        </template>
                      </el-table-column>
                    </el-table>
                    <div class="block changepages">
                      <el-pagination @size-change="handleSizeChange1" @current-change="handleCurrentChange1" :current-page="readQuery.page" :page-sizes="[20,30,40]"
                        :page-size="readQuery.pageCount" layout="total, sizes, prev, pager, next, jumper" :total="rowNumber1">
                      </el-pagination>
                    </div>
            </el-tab-pane>
             <el-tab-pane label="审核信息" name="third" v-if="(newOrEdit == 'look') && subcontractorForm.status != 2 ">
              <div id="myIframe" v-loading="loading1" v-if="reload" style = "text-align:center;">
                 <span style = "color:#909399;line-height:100px;" v-if = "WorkFlowMsg != '' && WorkFlowMsg != undefined" >{{WorkFlowMsg}}</span>
                <iframe :src="url" id="workFlowIframe" ref="workFlowIframe" width="100%" height="100%" frameborder="0" scrolling="auto"></iframe>
              </div>
            </el-tab-pane>

          </el-tabs>

        </div>
      </div>
    </div>
    <review-flow :addVisible.sync="reviewFlowShow" :reviewData="reviewData" :procInstType="procInstType" :reviewTitle="reviewTitle" @reloadMain="readSub"></review-flow>
    <addItem :addVisible.sync="addItemPop" :methodDetail.sync = "methodDetail" :subcontractorForm = "subcontractorForm" :newOrEditItem = "newOrEditItem"></addItem>
  </div>
</template>

<script>
import { mapState } from 'vuex'
const reviewFlow = () =>
  import('../../../common/reviewFlow.vue');
const addItem = () =>
  import('./children/addItem.vue');
export default {
  data() {
    return {

      subcontratorQuery: {
        page: 1, //第几页
        pageCount: 20, //页面得记录条数，
      },
      rowNumber: 0,
      subcontractorTable: [],
      subcontractorPop: false, //编辑弹出框
      enableStatusValue: '',
      searchName: '',
      newOrEdit: 'new',
      canEdit: true,
      subcontractorForm: {
        name: '',
        address: '',
        phone: "",
        contact: "",
        planAuditDate: '',
        haveCnas: false,
        haveCma: false,
        files: [],

      },
      subcontractorRules: {
        name: [
          { required: true, type: 'string', message: '请填写名称', trigger: 'blur' },
        ],
        phone: [{ required: true, message: '请填写电话', trigger: 'blur' },],
        contact: [{ required: true, message: '请填写联系人', trigger: 'blur' },],
      },
      // 设置当前日期之前的不可用
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7;
        }
      },
      attachmentPop: false,//附件弹出框
      attachmentTable: [],//附件表
      isStatus: '',
      isRepeat: true,
      activeTab: "first",
      reviewFlowShow: false, //审核流弹框
      reviewData: null, //点击行需要审核的信息
      procInstType: 't_subcontractor', //审核流要查的表
      reviewTitle: '分包商',
      url: "",
      reload: false,
      loading1: true,
      activeName: "first",
      methodsData:[],
      addItemPop:false,
      methodDetail:{},
      methodName:"",
      abilityName:"",
      rowNumber1:0,
      readQuery: {
        page: 1, //第几页
        pageCount: 20, //页面得记录条数，
      },
      newOrEditItem:"new",
      WorkFlowMsg:"",

    }
  },
  props: ["userOpernation"],
  components: {
    reviewFlow,addItem
  },
  computed: {
    ...mapState(['enableStatus', 'tableHeightA', 'sampleType', 'daibanItem', 'daibanItemShow']),
    sampleTypeTable() {
      let that = this;
      return that.$common.objToArr(that.sampleType);
    }
  },
  created() {
    this.readSubcontractors(this.subcontratorQuery);
    if (this.daibanItemShow) {
      this.editSubcontractor(this.daibanItem, 'review')
      this.$store.commit('passDaibanItemShow', false)
      // console.log(this.daibanItem)
    }
  },
  watch: {
    daibanItem(newer, older) {
      if (this.daibanItemShow) {
        this.editSubcontractor(this.daibanItem, 'review')
        this.$store.commit('passDaibanItemShow', false)
      }
    },
    subcontratorQuery: {
      handler(val, oldVal) {
        this.readSubcontractors(this.subcontratorQuery)
      },
      deep: true
    },
    activeName(val) {
      if (val == 'third') {
        this.reload = true;
        if (process.env.NODE_ENV == 'development') {

          this.url = "../../static/workflow.html?id=" + this.subcontractorForm.id + "&procInstType=" + this.procInstType + "&fromModel=look"

        } else {
          this.url = "static/workflow.html?id=" + this.subcontractorForm.id + "&procInstType=" + this.procInstType + "&fromModel=look"

        }
        var that = this;
        // setTimeout(function() {
        //   console.log(that.loading1)
          // let iframe = document.getElementById("workFlowIframe");
          window.addEventListener('message', that.handleMessage)
        // }, 3000)
      };
      if (val == 'second') {
        this.getSubconMethods();
      }
    },
    readQuery: {
      handler(val, oldVal) {
        this.getSubconMethods()
      },
      deep: true
    },
  },
  methods: {
    handleMessage(event) {
      const data = event.data
      switch (data.cmd) {
        case 'loadingHide':
          this.loading1 = false;
          this.WorkFlowMsg = "";
          break;
        case 'errorMsg': 
            this.loading1 = false;
            this.WorkFlowMsg = "没有查询到审核信息"
            break;  
      }
    },
    emptySearch() {
      this.searchName = '';
      this.enableStatusValue = '';
      this.readSubcontractors(this.subcontratorQuery)
    },
    //处理状态
    formatter(row, column, cellValue, index) {
      return this.util.changeStatus({ cellValue: cellValue, list: this.enableStatus })
    },
    // 处理时间
    formatterDate(row, column, cellValue) {
      if(cellValue){
        return this.util.formatterDate({ cellValue: cellValue })
      }else{
        return '---'
      }
    },
    //关闭
    close(formName) {
      this.subcontractorPop = false;
      this.$refs[formName].resetFields();
      this.subcontractorForm = {
        name: '',
        address: '',
        phone: "",
        contact: "",
        planAuditDate: '',
        haveCnas: false,
        haveCma: false,
        files: [],
      };
      this.isRepeat = true;
      this.reload = false;
      this.activeTab = "first";
      this.loading1 = true;
      this.activeName = "first";
      this.methodsData = [];
      this.WorkFlowMsg = "";

    },
    doSearch() {
      this.subcontratorQuery.page = 1;
      this.readSubcontractors(this.subcontratorQuery)
    },
    //读取分包商列表
    readSubcontractors(parp) {
      var params = {
        name: this.searchName,
        status: this.enableStatusValue,
        page: parp.page,
        pageCount: parp.pageCount,
      }
      this.$http({
        method: 'post',
        apiUrl: '/resource/readSubcontractorList.htm',
        params: params,
        isJson: true,
      }).then(res => {
        if (res.code == 0) {
          this.subcontractorTable = res.data;

          if (!res.pageinfo) {
            this.rowNumber = 0;
          } else if (res.pageinfo && !res.pageinfo.rowNumber) {
            this.rowNumber = 0;
          } else {
            this.rowNumber = res.pageinfo.rowNumber;
          }
        }

      })
    },
    // 添加分包商
    addsubcontractor() {
      this.subcontractorPop = true;
      this.newOrEdit = "new";
      this.canEdit = true;
    },
    //编辑查看分包商
    editSubcontractor(row, editOrLook) {
      this.subcontractorPop = true;
      this.newOrEdit = editOrLook;
      if (editOrLook == 'look' || editOrLook == 'review') {
        this.canEdit = false;
      } else {
        this.canEdit = true;
      }
      this.$http({
        method: 'post',
        apiUrl: '/resource/readSubcontractor.htm',
        params: { id: row.id },
        isJson: false,
      }).then(res => {
        if (res.code === 0) {
          res.data.files = res.data.fileList
          this.subcontractorForm = res.data;
          this.isStatus = this.subcontractorForm.status;
        }

      })
    },
    readSub() {
      this.$store.dispatch('getWorkflowList', 0).then(res => {
        this.$notify({
          showClose: true,
          message: '操作成功',
          type: 'success',
          title: "成功"
        })
      })
      this.close('subcontractorForm');
      this.readSubcontractors(this.subcontratorQuery)
    },
    reviewFlowPop(row) {
      this.reviewFlowShow = true;
      this.reviewData = this.subcontractorForm;
    },
    //提交添加
    submitSubcontractor(val) {
      this.$refs.subcontractorForm.validate((valid) => { //表单验证
        if (valid) {
          var formData = new FormData();
          for (var i in this.subcontractorForm.files) {
            formData.append("files", this.subcontractorForm.files[i])
          }

          formData.append("name", this.subcontractorForm.name);
          formData.append("address", this.subcontractorForm.address);
          formData.append("contact", this.subcontractorForm.contact)
          formData.append("phone", this.subcontractorForm.phone)
          formData.append("haveCnas", this.subcontractorForm.haveCnas)
          formData.append("haveCma", this.subcontractorForm.haveCma)
          formData.append("planAuditDate", this.subcontractorForm.planAuditDate)
          if (this.newOrEdit == 'new') {
            var url = '/resource/creatSubcontractor.htm';
            if (val == 'save') {
              formData.append("submitType", "0")
            } else {
              formData.append("submitType", "1")
            }
          } else {
            var url = '/resource/updateSubcontractor.htm';
            formData.append("id", this.subcontractorForm.id)
            var mes = "";
            if (val == 'save') {
              formData.append("submitType", "0")

            } else {
              formData.append("submitType", "1")
            }
          }
          var message = "";
          if (val == 'save') {
            message = "保存成功"
          } else {
            message = "提交成功"
          }

          this.isRepeat = false;
          this.$http({
            method: 'post',
            apiUrl: url,
            params: formData,
            headers: { 'Content-Type': 'multipart/form-data' }
          }).then(res => {
            this.isRepeat = true;
            if (res.code == 0) {
              this.$notify({
                title: "成功",
                type: 'success',
                message: message
              });
              if (val == 'save') {
                if(this.newOrEdit == 'new'){
                  this.subcontractorForm.id = res.data;
                }
                this.editSubcontractor(this.subcontractorForm,'edit')
              } else {
                this.close('subcontractorForm');
              }
              this.readSubcontractors(this.subcontratorQuery)
            }
          }).catch(() => {

          });

        } else {
          return false;
        }
      });
    },
    //删除分包商
    delSubcontractor(row) {
      this.$confirm('是否删除', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http({
          method: 'post',
          apiUrl: '/resource/deleteSubcontractor.htm',
          params: {
            id: row.id,
          },
          isJson: false,
        }).then(res => {
          if (res.code === 0) {
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            this.readSubcontractors(this.subcontratorQuery)
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });

    },
    uploadClick() { //上传
      document.getElementById("sub-file").click()
    },
    getFile(event) {   //上传 把文件加入到files数组（必须循环）
      for (var i = 0; i < event.target.files.length; i++) {
        event.target.files[i].fileName = event.target.files[i].name
        this.subcontractorForm.files.push(event.target.files[i])
      }
      event.target.value= "";
    },
    // 下载附件
    downloadattachment(row) {
      var url = "/download/fileDownload.htm"
      let token = sessionStorage.getItem('loginAccount')?sessionStorage.getItem('loginAccount'):undefined
      window.open(process.env.baseUrl + url + '?id=' + row.id + "&token=" + token);
    },
    deleteFileNew(index) {
      this.subcontractorForm.files.splice(index, 1)
    },
    deleteFileEdit(row, index) {  //如果
      this.$confirm('是否删除', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http({
          method: 'post',
          apiUrl: '/download/fileDelete.htm',
          params: {
            id: row.id,
          },
          isJson: false,
        }).then(res => {
          if (res.code === 0) {
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            this.subcontractorForm.files.splice(index, 1)
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },

    // 停用启用
    isStart(row) {
      var msg = row.status == 0 ? "启用" : "停用";
      this.$confirm("是否" + msg, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
      this.$http({
        method: 'post',
        apiUrl: '/resource/subcontractorStatus.htm',
        params: {
          id: row.id,
          status: row.status == 0 ? 1 : 0,
        },
        isJson: false,
      }).then(res => {
        if (res.code === 0) {
          this.readSubcontractors(this.subcontratorQuery)

        }

      })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消' + msg
        });
      });
    },
    handleSizeChange: function(val) {
      this.subcontratorQuery.pageCount = val;
    },
    handleCurrentChange: function(val) {
      this.subcontratorQuery.page = val;
    },
    changeHas: function(index, changeval, old) {
      this.subcontractorTable[index][changeval] = (old == 1) ? 0 : 1;
    },
    addAbility(){
      console.log(this.subcontractorForm)
      if(this.subcontractorForm.id == undefined){
          this.$notify({
            message: '请先保存基本信息',
            type: 'warning',
            title:"警告"
          });
          return;
      }
      this.newOrEditItem = 'new';
      this.addItemPop = true;
    },
    addItem(row,isEdit){
      this.newOrEditItem = isEdit;
      if(row.itemBeanList == undefined){
        row.itemBeanLis = [];
      }
       this.methodDetail = row
       this.addItemPop = true;
    },
    deleteMethod(row){
        this.$confirm('是否删除', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            method: 'post',
            apiUrl: '/resource/delSubconMethod.htm',
            params: {
              id: row.id,
              method:row.method,
            },
            isJson: false,
          }).then(res => {
            if (res.code === 0) {
              this.$message({
                type: 'success',
                message: '删除成功!'
              });
              this.getSubconMethods()
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
    },
    addSubconMethod(){
      console.log(this.subcontractorForm.id)
      if(this.subcontractorForm.id == undefined){
         this.$notify({
            message: '请先保存基本信息',
            type: 'warning',
            title:"警告"
          });
          return;
      }else{
        var params = {
          id:this.subcontractorForm.id,
          methodBeans:this.methodsData,
        }
        this.$http({
          method: 'post',
          apiUrl: '/resource/addSubconMethod.htm',
          params: params,
          isJson: true,
        }).then(res => {
          if (res.code === 0) {
              this.$notify({
                message: '保存成功',
                type: 'success',
                title:"保存"
              });
          }
        })
      }
    },
    doSearchMethod(){
      this.getSubconMethods();
    },
    getSubconMethods(){
      var params = {
          subcontractor:this.subcontractorForm.id,
          name:this.abilityName,
          methodName:this.methodName,
          page:this.readQuery.page,
          pageCount:this.readQuery.pageCount
      };
      this.$http({
          method: 'post',
          apiUrl: '/resource/getSubconMethods.htm',
          params: params,
          isJson: true,
        }).then(res => {
          if (res.code === 0) {
            this.methodsData = res.data
            if (!res.pageinfo) {
              this.rowNumber1 = 0;
            } else if (res.pageinfo && !res.pageinfo.rowNumber) {
              this.rowNumber1 = 0;
            } else {
              this.rowNumber1 = res.pageinfo.rowNumber;
            }
          }
        })

    },
     handleSizeChange1: function(val) {
      this.readQuery.pageCount = val;
    },
    handleCurrentChange1: function(val) {
      this.readQuery.page = val;
    },
  }
}

</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.el-form .el-form-item {
  display: inline-block;
  width: 49%;
  margin-bottom: 8px;
}

.seachTip .infoitem {
  width: calc(100%/3);
}

.seachTip .informationItem {
  width: calc(100% - 78px);
  float: none;
  margin-left: 8px;
}
</style>
<style>
.subcontractorPop .typeOfCard{
    height:100%;
}
.subcontractorPop .typeOfCard .el-tabs__content{
   height: calc(100% - 40px)
}
.subcontractorPop .typeOfCard .el-tabs__content .el-tab-pane {
  height: 100%
}
.subcontractorPop  .subForm {
  height: 160px;
  clear:both;
}

.subcontractorPop  .elTab {
  height: calc(100% - 200px)
}

.subcontractorPop  .elTab .el-tabs {
  height: 100%
}

.subcontractorPop  .elTab .el-tabs .el-tabs__content {
  height: calc(100% - 40px)
}

.subcontractorPop  .elTab .el-tabs .el-tabs__content .el-tab-pane {
  height: 100%
}

</style>